package com.ruoyi.web.core.config;

import com.ruoyi.common.config.RedisConfig;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.jedis.JedisLockProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * redis锁配置
 */

/**
 * @author wl
 * @date 2025年11月04日16:32
 */
@Data
@Slf4j
@Component
public class ShedLockConfig {

    @Autowired
    private RedisConfig redisConfig;

    @Bean
    public JedisPool createJedisPool() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        // 设置连接池配置...
        JedisPool jedisPool = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(), redisConfig.getDefaultTimeout(),redisConfig.getPassword(),redisConfig.getDatabase());
        return jedisPool;
    }

    @Bean
    public LockProvider createLockProvider(JedisPool jedisPool) {
        JedisLockProvider jedisLockProvider = new JedisLockProvider(jedisPool);
        return jedisLockProvider;
    }
}
